package park;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class J24ProfessorDAOImpl implements J24ProfessorDAO {
	
	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	
	// @앞에 id/pw 쓴다
	private static String URL = "jdbc:oracle:thin:pjandpd/pjandpd@112.216.253.124:1521:xe";
	
	private static String insertSQL = "";
	private static String selectSQL = " select * from professor oder by pfno ";
	private static String selectOneSQL = "";
	private static String updateSQL = "";
	private static String deleteSQL = "";
	

	@Override
	public String insertProfessor(J24ProfessorVO pvo) {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	//DB에 접속해서 테이블에 있는거 다 가져와서 배열 서비스 클래스로 전송하기 위해서
	@Override
	public ArrayList<J24ProfessorVO> selectProfessor() { 
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<J24ProfessorVO> pvose = null;
		
		try{
			conn = makeConn();
			pstmt = conn.prepareStatement(selectSQL);
			
			
			pvose = new ArrayList<>();
			while(rs.next()){
				J24ProfessorVO vo = new J24ProfessorVO();
					vo.setPfno(rs.getString(1));
					vo.setPfname(rs.getString(2));
					vo.setFields(rs.getString(3));
					vo.setSkills(rs.getString(4));
					vo.setRegdate(rs.getString(5));
				pvose.add(vo);
			}
			
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			closeConn(conn,pstmt,rs);
		}
		
		return pvose;
	}

	private void closeConn(Connection c, PreparedStatement p,
			ResultSet r) {

		if(r != null){
			try{
				
			}catch(Exception e){
				
			}
		}
		
		if(p != null){
			try{
				
			}catch(Exception e){
				
			}
		}
		
		if(c != null){
			try{
				
			}catch(Exception e){
				
			}
		}
		
	}


	@Override
	public ArrayList<J24ProfessorVO> selectOneProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String updateProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String deleteProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}

	
	
	
	
	private Connection makeConn() throws Exception{
		Connection conn = null;
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		return conn;
	}
		
	
	
}
